//
//  AMTabBar.m
//  AMwb
//
//  Created by zhc on 15/11/30.
//  Copyright © 2015年 zhc. All rights reserved.
//

#import "AMTabBar.h"

@interface AMTabBar()
@property(nonatomic,weak)UIButton *plusBtn;

@end


@implementation AMTabBar
- (id) initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if(self){
        //设置中间加号的背景图片和图片
        
        UIButton *plusbtn=[UIButton buttonWithType:UIButtonTypeCustom];
        [plusbtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [plusbtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateNormal];
       [plusbtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        [plusbtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        //按钮的大小等于背景图片的大小
        plusbtn.size=plusbtn.currentBackgroundImage.size;
      
        
        [self addSubview:plusbtn];
        
        
        self.plusBtn=plusbtn;
        
        
        [plusbtn addTarget:self action:@selector(plusclick) forControlEvents:UIControlEventTouchUpInside];
   
    }
    
    

    
    return  self;
    

}

- (void)plusclick{

    NSLog(@"click");
    if([self.delegate respondsToSelector:@selector(AMTabBarDidClickPlusButton:)]){
    
        [self.delegate AMTabBarDidClickPlusButton:self];
    
    
    }


}






- (void)layoutSubviews{

    [super layoutSubviews];
    
    
    self.plusBtn.centerX=self.width*0.5;
    self.plusBtn.centerY=self.height*0.5;
    CGFloat index=0;
    CGFloat width=self.width/5;
    
    //NSUInteger count=self.subviews.count;
    
    for(UIView *child in self.subviews){
        
        //UIView *child=self.subviews[i];
        
       // Class class=NSClassFromString(@"UITabBarButton");
        
        if([child isKindOfClass:NSClassFromString(@"UITabBarButton")]){
            child.width=width;
            child.x=index*width;
           
            index++;
            if(index == 2){
                index++;
            }
        
        }

}

}

@end
